﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Diagnostics;
using UIDesigner.DesignContainers.Bases;
using UIDesigner.Designers;
using UIDesigner.Editors;

namespace UIDesigner.SurfaceProperties
{
    public enum SurfaceResetPropertyKind
    {
        ResetOption,
        ResetConfirmOption
    }

    public class SurfaceResetDescriptor : PropertyDescriptor
    {
        private AFDesignerHost m_objHost;
        private SurfaceResetPropertyKind m_eKind;
        private IBaseObjectControl m_objControl;
        private SurfacePropertiesBase m_objSurrogateProperties;

        public SurfaceResetDescriptor(AFDesignerHost objHost, IBaseObjectControl objControl, SurfaceResetPropertyKind eKind, Attribute[] rgAttributes) : base(Enum.GetName(typeof(SurfaceResetPropertyKind), eKind), rgAttributes)
		{
            m_objHost = objHost;
            m_eKind = eKind;
            m_objControl = objControl;
        }

        public SurfaceResetDescriptor(AFDesignerHost objHost, IBaseObjectControl objControl, SurfaceResetPropertyKind eKind, Attribute[] rgAttributes, SurfacePropertiesBase objSurrogateProperties) : base(Enum.GetName(typeof(SurfaceResetPropertyKind), eKind), rgAttributes)
		{
            m_objHost = objHost;
            m_eKind = eKind;
            m_objControl = objControl;
            m_objSurrogateProperties = objSurrogateProperties;
        }

        private SurfacePropertiesBase SurfaceProperties
        {
            get
            {
                if (m_objSurrogateProperties == null)
                {
                    return m_objHost.SurfacePropertiesSet[m_objControl];
                }
                else
                {
                    return m_objSurrogateProperties;
                }
            }
        }

		public override bool CanResetValue(object component)
		{
			return true;
		}

		public override Type ComponentType
		{
			get 
            {
                return m_objHost.RootComponent.GetType(); 
            }
		}

		public override object GetValue(object component)
		{
            switch (m_eKind)
            {
                case SurfaceResetPropertyKind.ResetOption:
                    return new DynamicEnumType(m_objHost, m_objControl, typeof(ResetOptions), (int)this.SurfaceProperties.ResetProperties.ResetOptions );
                case SurfaceResetPropertyKind.ResetConfirmOption:
                    return this.SurfaceProperties.ResetProperties.ConfirmOptions;
                default:
                    Debugger.Break();
                    return null;
            }
		}

		public override bool IsReadOnly
		{
			get 
            {
                return false; 
            }
		}

		public override Type PropertyType
		{
			get 
            {
                switch (m_eKind)
                {
                    case SurfaceResetPropertyKind.ResetOption:
                        return typeof(DynamicEnumType);
                    case SurfaceResetPropertyKind.ResetConfirmOption:
                        return typeof(ConfirmOptions);
                    default:
                        Debugger.Break();
                        return null;
                }
            }
		}

		public override void ResetValue(object component)
		{
			
		}

		public override void SetValue(object component, object value)
		{
            if (value == null)
            {
                return;
            }

            switch (m_eKind)
            {
                case SurfaceResetPropertyKind.ResetOption:
                    this.SurfaceProperties.ResetProperties.ResetOptions = (ResetOptions)value;
                    break;
                case SurfaceResetPropertyKind.ResetConfirmOption:
                    this.SurfaceProperties.ResetProperties.ConfirmOptions = (ConfirmOptions)value; 
                    break;
                default:
                    Debugger.Break();
                    break;
            }
        }

		public override bool ShouldSerializeValue(object component)
		{
			return false;
		}

		public override string Category
		{
			get
			{
				return "Surface Properties";
			}
		}

		public override string DesignComments
		{
			get
			{
				return "Shows the hidden field names\r\nAlthough these properties exists at the selected object's type you cannot see them as editable";
			}
		}
    }
}
